﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.MediaCenter.Samples.MediaState;

namespace omaura_oled
{
    /// <summary>
    /// Call the functions to send data to the OLED
    /// </summary>
    public class DisplayClass
    {
        #region "Attributes"
        //--
        private OmauraOled OledInterface;
        private ReadConfigFile RCF;
        //--
        #endregion "Attributes"

        #region "Constructor"
        //--
        public DisplayClass(OmauraOled OledParent, ReadConfigFile RCF_parent)
        {
            OledInterface = OledParent;
            RCF = RCF_parent;
        }
        //--
        #endregion "Constructor"

        #region "Methods"
        //-- General Display
        public void restoreDisplay()
        {
            if (OledInterface.mediaState.MediaCenter.Active)
            {
                //-- display background
                if (OledInterface.mediaState.MediaCenter.Navigation == MediaStatusPropertyTag.FS_TV)
                    displayBkgndTVTuner();
                else if (OledInterface.mediaState.MediaCenter.Navigation == MediaStatusPropertyTag.FS_DVD)
                    displayBkgndDVD();
                else if (OledInterface.mediaState.MediaCenter.Navigation == MediaStatusPropertyTag.FS_Guide)
                    displayBkgndGuide();
                else if (OledInterface.mediaState.MediaCenter.Navigation == MediaStatusPropertyTag.FS_Music)
                    displayBkgndAudio();
                else if (OledInterface.mediaState.MediaCenter.Navigation == MediaStatusPropertyTag.FS_Photos)
                    displayBkgndPhotos();
                else if (OledInterface.mediaState.MediaCenter.Navigation == MediaStatusPropertyTag.FS_Videos)
                    displayBkgndVideo();
                else if (OledInterface.mediaState.MediaCenter.Navigation == MediaStatusPropertyTag.FS_Radio)
                    displayBkgndRadio();
                else if (OledInterface.mediaState.MediaCenter.Navigation == MediaStatusPropertyTag.FS_RecordedShows)
                    displayBkgndPVR();
                else
                    displayBkgndHome2();

                //-- display icon
                if (!OledInterface.timerVolumeDisplay.IsEnabled && !OledInterface.timerWeatherDisplay.IsEnabled && OledInterface.HomeDisplayed)
                {
                    if (OledInterface.mediaState.Music.Play
                        || OledInterface.mediaState.CD.Play
                        || OledInterface.mediaState.TV.Play
                        || OledInterface.mediaState.TVRecorded.Play
                        || OledInterface.mediaState.Radio.Play
                        || OledInterface.mediaState.DVD.Play
                        || OledInterface.mediaState.Video.Play
                        || OledInterface.mediaState.Pictures.Play
                        )
                        displayIconPlay();
                    if (OledInterface.mediaState.Music.Pause
                        || OledInterface.mediaState.CD.Pause
                        || OledInterface.mediaState.TV.Pause
                        || OledInterface.mediaState.TVRecorded.Pause
                        || OledInterface.mediaState.Radio.Pause
                        || OledInterface.mediaState.DVD.Pause
                        || OledInterface.mediaState.Video.Pause
                        || OledInterface.mediaState.Pictures.Pause
                        )
                        displayIconPause();
                    if (OledInterface.mediaState.Music.Stop
                        && OledInterface.mediaState.CD.Stop
                        && OledInterface.mediaState.TV.Stop
                        && OledInterface.mediaState.TVRecorded.Stop
                        && OledInterface.mediaState.Radio.Stop
                        && OledInterface.mediaState.DVD.Stop
                        && OledInterface.mediaState.Video.Stop
                        //-- added for no icon display when mediacenter shut down
                        && !OledInterface.mediaState.MediaCenter.Stop
                        )
                        displayIconStop();
                    if (!OledInterface.mediaState.Music.FastForward.ToString().Equals("Off")
                        || !OledInterface.mediaState.CD.FastForward.ToString().Equals("Off")
                        || !OledInterface.mediaState.TV.FastForward.ToString().Equals("Off")
                        || !OledInterface.mediaState.TVRecorded.FastForward.ToString().Equals("Off")
                        || !OledInterface.mediaState.Radio.FastForward.ToString().Equals("Off")
                        || !OledInterface.mediaState.DVD.FastForward.ToString().Equals("Off")
                        || !OledInterface.mediaState.Video.FastForward.ToString().Equals("Off")
                        || !OledInterface.mediaState.Pictures.FastForward.ToString().Equals("Off")
                        )
                        displayIconFF();
                    if (!OledInterface.mediaState.Music.Rewind.ToString().Equals("Off")
                        || !OledInterface.mediaState.CD.Rewind.ToString().Equals("Off")
                        || !OledInterface.mediaState.TV.Rewind.ToString().Equals("Off")
                        || !OledInterface.mediaState.TVRecorded.Rewind.ToString().Equals("Off")
                        || !OledInterface.mediaState.Radio.Rewind.ToString().Equals("Off")
                        || !OledInterface.mediaState.DVD.Rewind.ToString().Equals("Off")
                        || !OledInterface.mediaState.Video.Rewind.ToString().Equals("Off")
                        || !OledInterface.mediaState.Pictures.Rewind.ToString().Equals("Off")
                        )
                        displayIconRW();
                }
            }
            else
            {
                OledInterface.timerTimeCurrent.Start();
            }
            System.Threading.Thread.Sleep(100);
        }
        public void displayProgressBar()
        {
            int trackTime, trackDuration;
            //-- CD
            if (OledInterface.mediaState.CD.Active)
            {
                trackTime = OledInterface.mediaState.CD.TrackTime;
                trackDuration = OledInterface.mediaState.CD.TrackDuration;
            }

            //-- Music
            else if (OledInterface.mediaState.Music.Active)
            {
                trackTime = OledInterface.mediaState.Music.TrackTime;
                trackDuration = OledInterface.mediaState.Music.TrackDuration;
            }

            //-- Video 
            else if (OledInterface.mediaState.Video.Active)
            {
                trackTime = OledInterface.mediaState.Video.TrackTime;
                trackDuration = OledInterface.mediaState.Video.MediaTime;
            }

            //-- DVD
            else if (OledInterface.mediaState.DVD.Active)
            {
                trackTime = OledInterface.mediaState.DVD.TrackTime;
                trackDuration = OledInterface.mediaState.DVD.MediaTime;
            }

            //-- TV
            else if (OledInterface.mediaState.TV.Active)
            {
                trackTime = OledInterface.mediaState.TV.TrackTime;
                trackDuration = OledInterface.mediaState.TV.MediaTime;
            }

            //-- TV Recorded
            else if (OledInterface.mediaState.TVRecorded.Active)
            {
                trackTime = OledInterface.mediaState.TVRecorded.TrackTime;
                trackDuration = OledInterface.mediaState.TVRecorded.MediaTime;
            }

            //-- Other Cases
            else
            {
                trackTime = 0;
                trackDuration = 0;
            }
            //--
            if (trackDuration != 0)
            {
                int position = (int)((float)((float)trackTime / (float)trackDuration) * 240);
                IconsManager im = OledInterface.getIconManager();
                im.sendProgressBar(position, 4, 2);
            }
        }
        public void displayTimeEmpty()
        {
            string formatedTime = "";

            //-- complet to not have some strange display
            if (formatedTime.Length < 19)
                for (int i = formatedTime.Length - 1; i < 19; i++)
                    formatedTime += " ";

            IconsManager im = OledInterface.getIconManager();
            im.sendBitmapText(formatedTime, RCF.get_xTimer(), RCF.get_yTimer(), RCF.get_TextSize(), false, false);

            displayProgressBar();
        }
        public void displayTime(int time)
        {
            if (!OledInterface.timerVolumeDisplay.IsEnabled && !OledInterface.timerWeatherDisplay.IsEnabled)// && (parent.mediaState.getMenuState() != "FS_HOME"))
            {
                int eSeconds = 0, eMinutes = 0, eHours = 0;
                string eSecondsStr;
                string formatedTime;
                string sign = "";

                if (time < 0)
                {
                    time = 0 - time;
                    sign = "-";
                }

                // Convert in seconds, minutes and hours
                eSeconds = time % 60;
                time -= eSeconds;
                time = time / 60;
                eMinutes = time % 60;
                time -= eMinutes;
                time = time / 60;
                eHours = time;

                if (eSeconds >= 10)
                    eSecondsStr = eSeconds.ToString();
                else
                    eSecondsStr = "0" + eSeconds.ToString();


                if (eHours != 0)
                {
                    if (eMinutes < 10)
                        formatedTime = sign + eHours.ToString() + ":0" + eMinutes.ToString() + ":" + eSecondsStr;
                    else
                        formatedTime = sign + eHours.ToString() + ":" + eMinutes.ToString() + ":" + eSecondsStr;
                }
                else
                    formatedTime = sign + eMinutes.ToString() + ":" + eSecondsStr;

                //-- complet to not have some strange display
                if (formatedTime.Length < 19)
                    for (int i = formatedTime.Length - 1; i < 19; i++)
                        formatedTime += " ";

                IconsManager im = OledInterface.getIconManager();
                im.sendBitmapText(formatedTime, RCF.get_xTimer(), RCF.get_yTimer(), RCF.get_TextSize(), false, false);

                displayProgressBar();
            }
        }
        public void displayTimeAndTotal(int time, int totaltime)
        {
            if (!OledInterface.timerVolumeDisplay.IsEnabled && !OledInterface.timerWeatherDisplay.IsEnabled)// && (parent.mediaState.getMenuState() != "FS_HOME"))
            {
                int eSeconds = 0, eMinutes = 0, eHours = 0;
                int tSeconds = 0, tMinutes = 0, tHours = 0;
                string eSecondsStr, tSecondsStr;
                string formatedTime;
                string sign = "";

                if (time < 0)
                {
                    time = 0 - time;
                    sign = "-";
                }

                // Convert in seconds, minutes and hours the current time
                eSeconds = time % 60;
                time -= eSeconds;
                time = time / 60;
                eMinutes = time % 60;
                time -= eMinutes;
                time = time / 60;
                eHours = time;
                
                if (eSeconds >= 10)
                    eSecondsStr = eSeconds.ToString();
                else
                    eSecondsStr = "0" + eSeconds.ToString();

                if (eHours != 0)
                {
                    if(eMinutes < 10)
                        formatedTime = sign + eHours.ToString() + ":0" + eMinutes.ToString() + ":" + eSecondsStr;
                    else
                        formatedTime = sign + eHours.ToString() + ":" + eMinutes.ToString() + ":" + eSecondsStr;
                }
                else
                    formatedTime = sign + eMinutes.ToString() + ":" + eSecondsStr;


                // Convert in seconds, minutes and hours the total time
                tSeconds = totaltime % 60;
                totaltime -= tSeconds;
                totaltime = totaltime / 60;
                tMinutes = totaltime % 60;
                totaltime -= tMinutes;
                totaltime = totaltime / 60;
                tHours = totaltime;

                if (tSeconds >= 10)
                    tSecondsStr = tSeconds.ToString();
                else
                    tSecondsStr = "0" + tSeconds.ToString();

                if (tHours != 0)
                {
                    if(tMinutes < 10)
                        formatedTime += " / " + tHours.ToString() + ":0" + tMinutes.ToString() + ":" + tSecondsStr + " ";
                    else
                        formatedTime += " / " + tHours.ToString() + ":" + tMinutes.ToString() + ":" + tSecondsStr + " ";
                }
                else
                    formatedTime += " / " + tMinutes.ToString() + ":" + tSecondsStr + " ";

                //-- complet to not have some strange display
                if (formatedTime.Length < 19)
                    for (int i = formatedTime.Length - 1; i < 19; i++)
                        formatedTime += " ";

                IconsManager im = OledInterface.getIconManager();
                im.sendBitmapText(formatedTime, RCF.get_xTimer(), RCF.get_yTimer(), RCF.get_TextSize(), false, false);

                displayProgressBar();
            }
        }
        public void displayCurrentTime()
        {
            string formatedTime = "";

            if(!OledInterface.ScriptRead.TimeCurrent.Equals(""))
                formatedTime = System.DateTime.Now.ToString(OledInterface.ScriptRead.TimeCurrent.ToString());
            else
                formatedTime = System.DateTime.Now.ToString();

            IconsManager im = OledInterface.getIconManager();
            im.sendBitmapText(formatedTime, RCF.get_xClock(), RCF.get_yClock(), 4, false, true);
        }
        public void displayVolume(int volume)
        {
            //-- parameters
            int textPositionX = 100;
            int textPositionY = 22;
            string VolumeTextData = "";

            if (!OledInterface.timerVolumeDisplay.IsEnabled && !OledInterface.timerWeatherDisplay.IsEnabled)
            {
                eraseScreen();
                OledInterface.timerVolumeDisplay.IsEnabled = true;
            }
            else
                OledInterface.timerVolumeDisplay_Counter = 0;

            IconsManager im = OledInterface.getIconManager();

            //-- display progress bar
            //--- evaluate the sound position to send
            int soundCorrected = (volume * 120) / 50;
            //--- send the data for the progress bar sound
            im.sendProgressBarSound(soundCorrected, 32, 30);

            //-- display icon
            displayIconSound();
            
            //-- create the text data
            if (volume == 0)
                VolumeTextData = "mute";
            else if (volume == 50)
                VolumeTextData = "max ";
            else
            {
                VolumeTextData = volume.ToString();

                for (int i = VolumeTextData.Length; i < 6; i++)
                    VolumeTextData += " ";
            }

            //-- display text
            im.sendBitmapText(VolumeTextData, textPositionX, textPositionY, RCF.get_TextSize(), false, false);
        }
        public void displayTitle(string text)
        {
            if (!OledInterface.timerVolumeDisplay.IsEnabled && !OledInterface.timerWeatherDisplay.IsEnabled)
            {
                if (OledInterface.timerScrollingText.IsEnabled)
                    OledInterface.timerScrollingText.IsEnabled = false;

                IconsManager im = OledInterface.getIconManager();
                im.sendBitmapText(text, RCF.get_xText(), RCF.get_yText(), RCF.get_TextSize(), true, true);
            }
        }
        public void eraseScreen()
        {
            if (OledInterface.serialPort1.IsOpen)
            {
                byte[] buffer = new byte[2];
                buffer[0] = 0x70; // Start code
                buffer[1] = 0x80; // Erase code
                OledInterface.serialPort1.Write(buffer, 0, 2);
            }
            // prevent form port com crash
            System.Threading.Thread.Sleep(100);
        }

        //-- Api Display (special)
        public void displayProgressBar_API(int timeCurrent, int timeTotal)
        {
            int position = (int)((float)((float)timeCurrent / (float)timeTotal) * 240);
            IconsManager im = OledInterface.getIconManager();
            im.sendProgressBar(position, 4, 2);
        }
        public void displayTime_API(int time)
        {
            if (!OledInterface.timerVolumeDisplay.IsEnabled && !OledInterface.timerWeatherDisplay.IsEnabled)// && (parent.mediaState.getMenuState() != "FS_HOME"))
            {
                int eSeconds = 0, eMinutes = 0, eHours = 0;
                string eSecondsStr;
                string formatedTime;
                string sign = "";

                if (time < 0)
                {
                    time = 0 - time;
                    sign = "-";
                }

                // Convert in seconds, minutes and hours
                eSeconds = time % 60;
                time -= eSeconds;
                time = time / 60;
                eMinutes = time % 60;
                time -= eMinutes;
                time = time / 60;
                eHours = time;

                if (eSeconds >= 10)
                    eSecondsStr = eSeconds.ToString();
                else
                    eSecondsStr = "0" + eSeconds.ToString();


                if (eHours != 0)
                {
                    if (eMinutes < 10)
                        formatedTime = sign + eHours.ToString() + ":0" + eMinutes.ToString() + ":" + eSecondsStr;
                    else
                        formatedTime = sign + eHours.ToString() + ":" + eMinutes.ToString() + ":" + eSecondsStr;
                }
                else
                    formatedTime = sign + eMinutes.ToString() + ":" + eSecondsStr;

                //-- complet to not have some strange display
                if (formatedTime.Length < 19)
                    for (int i = formatedTime.Length - 1; i < 19; i++)
                        formatedTime += " ";

                IconsManager im = OledInterface.getIconManager();
                im.sendBitmapText(formatedTime, RCF.get_xTimer(), RCF.get_yTimer(), RCF.get_TextSize(), false, false);
            }
        }
        public void displayTimeAndTotal_API(int time, int totaltime)
        {
            if (!OledInterface.timerVolumeDisplay.IsEnabled && !OledInterface.timerWeatherDisplay.IsEnabled)// && (parent.mediaState.getMenuState() != "FS_HOME"))
            {
                int eSeconds = 0, eMinutes = 0, eHours = 0;
                int tSeconds = 0, tMinutes = 0, tHours = 0;
                string eSecondsStr, tSecondsStr;
                string formatedTime;
                string sign = "";

                if (time < 0)
                {
                    time = 0 - time;
                    sign = "-";
                }

                // Convert in seconds, minutes and hours the current time
                eSeconds = time % 60;
                time -= eSeconds;
                time = time / 60;
                eMinutes = time % 60;
                time -= eMinutes;
                time = time / 60;
                eHours = time;

                if (eSeconds >= 10)
                    eSecondsStr = eSeconds.ToString();
                else
                    eSecondsStr = "0" + eSeconds.ToString();

                if (eHours != 0)
                {
                    if (eMinutes < 10)
                        formatedTime = sign + eHours.ToString() + ":0" + eMinutes.ToString() + ":" + eSecondsStr;
                    else
                        formatedTime = sign + eHours.ToString() + ":" + eMinutes.ToString() + ":" + eSecondsStr;
                }
                else
                    formatedTime = sign + eMinutes.ToString() + ":" + eSecondsStr;


                // Convert in seconds, minutes and hours the total time
                tSeconds = totaltime % 60;
                totaltime -= tSeconds;
                totaltime = totaltime / 60;
                tMinutes = totaltime % 60;
                totaltime -= tMinutes;
                totaltime = totaltime / 60;
                tHours = totaltime;

                if (tSeconds >= 10)
                    tSecondsStr = tSeconds.ToString();
                else
                    tSecondsStr = "0" + tSeconds.ToString();

                if (tHours != 0)
                {
                    if (tMinutes < 10)
                        formatedTime += " / " + tHours.ToString() + ":0" + tMinutes.ToString() + ":" + tSecondsStr + " ";
                    else
                        formatedTime += " / " + tHours.ToString() + ":" + tMinutes.ToString() + ":" + tSecondsStr + " ";
                }
                else
                    formatedTime += " / " + tMinutes.ToString() + ":" + tSecondsStr + " ";

                //-- complet to not have some strange display
                if (formatedTime.Length < 19)
                    for (int i = formatedTime.Length - 1; i < 19; i++)
                        formatedTime += " ";

                IconsManager im = OledInterface.getIconManager();
                im.sendBitmapText(formatedTime, RCF.get_xTimer(), RCF.get_yTimer(), RCF.get_TextSize(), false, false);
            }
        }
        public void displayVolume_API(int volume)
        {
            //OledInterface.API_Oled.Interrupt = true;

            OledInterface.timerScrollingText.Stop();

            //-- parameters
            int textPositionX = 100;
            int textPositionY = 22;
            string VolumeTextData = "";

            if (!OledInterface.timerVolumeDisplay.IsEnabled && !OledInterface.timerWeatherDisplay.IsEnabled)
            {
                eraseScreen();
                OledInterface.timerVolumeDisplay.IsEnabled = true;
            }
            else
                OledInterface.timerVolumeDisplay_Counter = 0;

            IconsManager im = OledInterface.getIconManager();

            //-- display progress bar
            //--- evaluate the sound position to send
            int soundCorrected = (volume * 120) / 50;
            //--- send the data for the progress bar sound
            im.sendProgressBarSound(soundCorrected, 32, 30);

            //-- display icon
            displayIconSound();

            //-- create the text data
            if (volume == 0)
                VolumeTextData = "mute";
            else if (volume == 50)
                VolumeTextData = "max ";
            else
            {
                VolumeTextData = volume.ToString();

                for (int i = VolumeTextData.Length; i < 6; i++)
                    VolumeTextData += " ";
            }

            //-- display text
            im.sendBitmapText(VolumeTextData, textPositionX, textPositionY, RCF.get_TextSize(), false, false);
        }

        public void displayCity_API(string text)
        {
            OledInterface.API_Oled.Interrupt = true;

            if (!OledInterface.timerVolumeDisplay.IsEnabled && !OledInterface.timerWeatherDisplay.IsEnabled)
            {
                if (OledInterface.timerScrollingText.IsEnabled)
                    OledInterface.timerScrollingText.IsEnabled = false;

                IconsManager im = OledInterface.getIconManager();
                im.sendBitmapText(text, 0, 10, RCF.get_TextSize(), false, false);
            }
        }
        public void displayTemperature_API(int temperature)
        {
            OledInterface.API_Oled.Interrupt = true;

            if (!OledInterface.timerVolumeDisplay.IsEnabled && !OledInterface.timerWeatherDisplay.IsEnabled)
            {
                string TemperatureToDisplay = "";

                //--celcius/farenheit
                if (OledInterface.RCF.WeatherTemperatureInCelcius == 1)
                    TemperatureToDisplay = ((temperature - 32) * 5 / 9).ToString() + " ºC";
                else
                    TemperatureToDisplay = temperature.ToString() + " ºF";
                IconsManager im = OledInterface.getIconManager();
                im.sendBitmapText(TemperatureToDisplay, 0, 40, RCF.get_TextSize(), false, false);
            }
        }
        public void displayWeather_API()
        {
            OledInterface.API_Oled.Interrupt = true;

            OledInterface.timerScrollingText.Stop();

            /*
            if (!OledInterface.timerVolumeDisplay.IsEnabled 
                && !OledInterface.timerWeatherDisplay.IsEnabled)
            {
                //eraseScreen();
                //displayTitle(" ");
                OledInterface.timerWeatherDisplay.IsEnabled = true;
            }
            */
            displayCity(OledInterface.weather.City);
            displayTemperature(OledInterface.weather.Temperature);

            if (OledInterface.weather.WeatherIcon < 10)
                displayLogo(OledInterface.weather.PathToWeatherImages + "0" + OledInterface.weather.WeatherIcon + ".bmp", 191, 6);
            else
                displayLogo(OledInterface.weather.PathToWeatherImages + OledInterface.weather.WeatherIcon + ".bmp", 191, 6);
        }

        public void restoreDisplay_API()
        {
            eraseScreen_API();

            #region "background"
            //--

            switch (OledInterface.API_Oled.Session)
            {
                case "home":
                    displayBkgndHome();
                    break;
                case "home2":
                    displayBkgndHome2();
                    break;
                case "guide":
                    displayBkgndGuide();
                    break;
                case "dvd":
                    displayBkgndDVD();
                    break;
                case "cd":
                    displayBkgndCD();
                    break;
                case "pvr":
                    displayBkgndPVR();
                    break;
                case "music":
                    displayBkgndAudio();
                    break;
                case "video":
                    displayBkgndVideo();
                    break;
                case "tv":
                    displayBkgndTVTuner();
                    break;
                case "pictures":
                    displayBkgndPhotos();
                    break;
                case "radio":
                    displayBkgndRadio();
                    break;
            }

            #endregion "background"

            #region "icon"
            //--
            switch (OledInterface.API_Oled.Status)
            {
                case "play":
                    OledInterface.displayClass.displayIconPlay();
                    break;
                case "pause":
                    OledInterface.displayClass.displayIconPause();
                    break;
                case "stop":
                    OledInterface.displayClass.displayIconStop();
                    break;
                case "record":
                    OledInterface.displayClass.displayIconRecord();
                    break;
                case "rewind":
                    OledInterface.displayClass.displayIconRW();
                    break;
                case "forward":
                    OledInterface.displayClass.displayIconFF();
                    break;
            }

            #endregion "icon"

            #region "title"
            //--
            displayTitle(OledInterface.API_Oled.Title);

            #endregion "title"

            #region "time&progress"
            //--
            if (OledInterface.API_Oled.MediaTime > 0)
            {
                displayTimeAndTotal_API(OledInterface.API_Oled.MediaTime, 
                    OledInterface.API_Oled.MediaTotalTime);
                displayProgressBar_API(OledInterface.API_Oled.MediaTime, 
                    OledInterface.API_Oled.MediaTotalTime);
            }
            else
            {
                displayTimeAndTotal_API(OledInterface.API_Oled.MediaTime, 
                    OledInterface.API_Oled.MediaTotalTime);
                displayProgressBar_API(OledInterface.API_Oled.MediaTime + OledInterface.API_Oled.MediaTotalTime, 
                    OledInterface.API_Oled.MediaTotalTime);
            }


            #endregion "time&progress"

            OledInterface.API_Oled.Interrupt = false;
        }
        public void eraseScreen_API()
        {
            OledInterface.timerScrollingText.IsEnabled = false;

            if (OledInterface.serialPort1.IsOpen)
            {
                byte[] buffer = new byte[2];
                buffer[0] = 0x70; // Start code
                buffer[1] = 0x80; // Erase code
                OledInterface.serialPort1.Write(buffer, 0, 2);
            }
        }

        //-- Display Backgrounds
        public void displayBkgndHome()
        {
            if (!OledInterface.timerVolumeDisplay.IsEnabled && !OledInterface.timerWeatherDisplay.IsEnabled)
            {
                IconsManager im = OledInterface.getIconManager();
                im.sendBackgroundData("Home");
            }
        }
        public void displayBkgndHome2()
        {
            if (!OledInterface.timerVolumeDisplay.IsEnabled && !OledInterface.timerWeatherDisplay.IsEnabled)
            {
                IconsManager im = OledInterface.getIconManager();
                im.sendBackgroundData("Home2");
            }
        }
        public void displayBkgndGuide()
        {
            if (!OledInterface.timerVolumeDisplay.IsEnabled && !OledInterface.timerWeatherDisplay.IsEnabled)
            {
                IconsManager im = OledInterface.getIconManager();
                im.sendBackgroundData("Guide");
            }
        }
        public void displayBkgndDVD()
        {
            if (!OledInterface.timerVolumeDisplay.IsEnabled && !OledInterface.timerWeatherDisplay.IsEnabled)
            {
                IconsManager im = OledInterface.getIconManager();
                im.sendBackgroundData("DVD");
            }
        }
        public void displayBkgndCD()
        {
            if (!OledInterface.timerVolumeDisplay.IsEnabled && !OledInterface.timerWeatherDisplay.IsEnabled)
            {
                IconsManager im = OledInterface.getIconManager();
                im.sendBackgroundData("CD");
            }
        }
        public void displayBkgndPVR()
        {
            if (!OledInterface.timerVolumeDisplay.IsEnabled && !OledInterface.timerWeatherDisplay.IsEnabled)
            {
                IconsManager im = OledInterface.getIconManager();
                im.sendBackgroundData("PVR");
            }
        }
        public void displayBkgndAudio()
        {
            if (!OledInterface.timerVolumeDisplay.IsEnabled && !OledInterface.timerWeatherDisplay.IsEnabled)
            {
                IconsManager im = OledInterface.getIconManager();
                im.sendBackgroundData("Audio");
            }
        }
        public void displayBkgndVideo()
        {
            if (!OledInterface.timerVolumeDisplay.IsEnabled && !OledInterface.timerWeatherDisplay.IsEnabled)
            {
                IconsManager im = OledInterface.getIconManager();
                im.sendBackgroundData("Video");
            }
        }
        public void displayBkgndTVTuner()
        {
            if (!OledInterface.timerVolumeDisplay.IsEnabled && !OledInterface.timerWeatherDisplay.IsEnabled)
            {
                IconsManager im = OledInterface.getIconManager();
                im.sendBackgroundData("TVTuner");
            }
        }
        public void displayBkgndPhotos()
        {
            if (!OledInterface.timerVolumeDisplay.IsEnabled && !OledInterface.timerWeatherDisplay.IsEnabled)
            {
                IconsManager im = OledInterface.getIconManager();
                im.sendBackgroundData("Photos");
            }
        }
        public void displayBkgndRadio()
        {
            if (!OledInterface.timerVolumeDisplay.IsEnabled && !OledInterface.timerWeatherDisplay.IsEnabled)
            {
                IconsManager im = OledInterface.getIconManager();
                im.sendBackgroundData("Radio");
            }
        }
        //--- display death image
        public void displayDeathImage()
        {
            if (!OledInterface.timerVolumeDisplay.IsEnabled && !OledInterface.timerWeatherDisplay.IsEnabled)
            {
                IconsManager im = OledInterface.getIconManager();
                im.sendBackgroundData("Death");
            }
        }

        //-- Display Image
        public void displayImage(string pathToImage)
        {
            if (!OledInterface.timerVolumeDisplay.IsEnabled && !OledInterface.timerWeatherDisplay.IsEnabled)
            {
                IconsManager im = OledInterface.getIconManager();
                im.sendImage(pathToImage);
            }
        }
        public void displayLogo(string pathToImage)
        {
            if (!OledInterface.timerVolumeDisplay.IsEnabled && !OledInterface.timerWeatherDisplay.IsEnabled)
            {
                IconsManager im = OledInterface.getIconManager();
                im.sendLogo(pathToImage);
            }
        }
        public void displayLogo(string pathToImage, int x, int y)
        {
            if (!OledInterface.timerVolumeDisplay.IsEnabled && !OledInterface.timerWeatherDisplay.IsEnabled)
            {
                IconsManager im = OledInterface.getIconManager();
                im.sendLogo(pathToImage,x,y);
            }
        }

        //-- Display Weather
        public void displayCity(string text)
        {
            if (!OledInterface.timerVolumeDisplay.IsEnabled && !OledInterface.timerWeatherDisplay.IsEnabled)
            {
                if (OledInterface.timerScrollingText.IsEnabled)
                    OledInterface.timerScrollingText.IsEnabled = false;

                IconsManager im = OledInterface.getIconManager();
                im.sendBitmapText(text, 0, 10, RCF.get_TextSize(), false, false);
            }
        }
        public void displayTemperature(int temperature)
        {
            if (!OledInterface.timerVolumeDisplay.IsEnabled && !OledInterface.timerWeatherDisplay.IsEnabled)
            {
                string TemperatureToDisplay = "";

                //--celcius/farenheit
                if (OledInterface.RCF.WeatherTemperatureInCelcius == 1)
                    TemperatureToDisplay = ((temperature - 32) * 5 /9).ToString() + " ºC";
                else
                    TemperatureToDisplay = temperature.ToString() + " ºF";
                IconsManager im = OledInterface.getIconManager();
                im.sendBitmapText(TemperatureToDisplay, 0, 40, RCF.get_TextSize(), false, false);
            }
        }
        public void displayWeather()
        {
            displayCity(OledInterface.weather.City);
            displayTemperature(OledInterface.weather.Temperature);

            if (OledInterface.weather.WeatherIcon < 10)
                displayLogo(OledInterface.weather.PathToWeatherImages + "0" + OledInterface.weather.WeatherIcon + ".bmp", 191, 6);
            else
                displayLogo(OledInterface.weather.PathToWeatherImages + OledInterface.weather.WeatherIcon + ".bmp", 191, 6);
        }

        //-- Display Icons
        public void displayIconPlay()
        {
            IconsManager im = OledInterface.getIconManager();
            im.sendIcondata("Play", RCF.get_xIcon(), RCF.get_yIcon());
        }
        public void displayIconPause()
        {
            IconsManager im = OledInterface.getIconManager();
            im.sendIcondata("Pause", RCF.get_xIcon(), RCF.get_yIcon());
        }
        public void displayIconStop()
        {
            if (!OledInterface.timerVolumeDisplay.IsEnabled && !OledInterface.timerWeatherDisplay.IsEnabled)
            {
                IconsManager im = OledInterface.getIconManager();
                im.sendIcondata("Stop", RCF.get_xIcon(), RCF.get_yIcon());
            }
        }
        public void displayIconRecord()
        {
            if (!OledInterface.timerVolumeDisplay.IsEnabled && !OledInterface.timerWeatherDisplay.IsEnabled)
            {
                IconsManager im = OledInterface.getIconManager();
                im.sendIcondata("Record", RCF.get_xIcon(), RCF.get_yIcon());
            }
        }
        public void displayIconRW()
        {
            if (!OledInterface.timerVolumeDisplay.IsEnabled && !OledInterface.timerWeatherDisplay.IsEnabled)
            {
                IconsManager im = OledInterface.getIconManager();
                im.sendIcondata("RW", RCF.get_xIcon(), RCF.get_yIcon());
            }
        }
        public void displayIconFF()
        {
            if (!OledInterface.timerVolumeDisplay.IsEnabled && !OledInterface.timerWeatherDisplay.IsEnabled)
            {
                IconsManager im = OledInterface.getIconManager();
                im.sendIcondata("FF", RCF.get_xIcon(), RCF.get_yIcon());
            }
        }
        public void displayIconSound()
        {
            IconsManager im = OledInterface.getIconManager();
            im.sendIcondata("Sound", 8, 16);
        }

        //--
        #endregion "Methods"
    }
}
